﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="NewService.aspx.cs" Inherits="MonkeyWarranty.Web.InstantTickets.NewService" %>

<%@ Import Namespace="Resources" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <title>
        <%=GlobalStrings.InstantTicketForm %> - <%=GlobalStrings.Services %></title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="row">
        <div class="col-lg-12">
            <h3><%=GlobalStrings.OutsideService %></h3>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="alert alert-danger" runat="server" id="errorMessage" visible="False">
                <label class="control-label">
                    <asp:Literal ID="lblErrorMessage" runat="server"></asp:Literal></label>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <%=GlobalStrings.InstantTicketForm %>
                </div>
                <div class="panel-body">
                    <div class="col-lg-6">
                        <p>Số phiếu: <a href="Edit.aspx?id=<%=Request.Params["ticketId"] %>#tabs-1"><asp:Literal ID="ltrTicketCode" runat="server"></asp:Literal></a></p>
                        <p>Nội dung: <asp:Literal ID="ltrContent" runat="server"></asp:Literal></p>
                        <p>Ngày nhận: <asp:Literal ID="ltrReceivedDate" runat="server"></asp:Literal></p>
                        <p>Khoảng cách: <asp:Literal ID="ltrDistance" runat="server"></asp:Literal></p>
                        <p>Mô tả: <asp:Literal ID="ltrDescription" runat="server"></asp:Literal></p>
                    </div>
                    <div class="col-lg-6">
                        <p>Khách hàng: <asp:Literal ID="ltrCustomerName" runat="server"></asp:Literal></p>
                        <p>Địa chỉ: <asp:Literal ID="ltrCustomerAddress" runat="server"></asp:Literal></p>
                        <p>Điện thoại: <asp:Literal ID="ltrCustomerPhone" runat="server"></asp:Literal></p>
                        <p>Email: <asp:Literal ID="ltrCustomerEmail" runat="server"></asp:Literal></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <%=GlobalStrings.OutsideService %>
                </div>
                <div class="panel-body">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <asp:HiddenField ID="hidServiceId" runat="server" />
                            <label><%=GlobalStrings.Services%></label>
                            <a class="btn btn-info" href="javascript:void(0);" onclick="javascript:SelectService();" data-toggle="modal" data-target="#serviceModal">Chọn...</a>
                            <p></p><asp:TextBox ID="txtServiceName" runat="server" ReadOnly="True" CssClass="form-control"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtServiceName"
                                CssClass="failureNotification" ValidationGroup="AddNew">(*)</asp:RequiredFieldValidator>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label><%=GlobalStrings.Quantity %></label>
                            <asp:TextBox ID="txtQuantity" runat="server" CssClass="form-control" Text="1"></asp:TextBox>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.ServiceType %></label>
                            <asp:DropDownList ID="ddlServiceTypes" runat="server" CssClass="form-control"></asp:DropDownList>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.ErrorCode %></label>
                            <asp:DropDownList ID="ddlErrors" runat="server" CssClass="form-control"></asp:DropDownList>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.TechnicalEmployees %></label><br />
                            <asp:DropDownList ID="ddlEmployees" runat="server" CssClass="form-control"></asp:DropDownList>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.StartDate %></label><br />
                            <asp:TextBox ID="txtStartDate" runat="server"></asp:TextBox>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.EndDate %></label><br />
                            <asp:TextBox ID="txtEndDate" runat="server"></asp:TextBox>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label><%=GlobalStrings.Description %></label>
                            <asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" CssClass="form-control"></asp:TextBox>
                        </div>
                        <div class="form-group">
                            <label><%=GlobalStrings.Note %></label>
                            <asp:TextBox ID="txtNote" TextMode="MultiLine" runat="server" CssClass="form-control"></asp:TextBox>
                        </div>
                    </div>

                    <div class="col-lg-12">
                        <asp:Button ID="btnSave" runat="server"
                            Text="<%$ Resources:GlobalStrings, Save %>" CssClass="btn btn-primary" Width="100px"
                            OnClick="btnSave_Click" />
                        <a class="btn btn-default" href="Edit.aspx?id=<%=Request.Params["ticketId"] %>#tabs-1"><%=GlobalStrings.Cancel %></a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Services Modal -->
    <div class="modal fade" id="serviceModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog" style="width: 850px; height: 400px;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel"><%=GlobalStrings.ServicesList %></h4>
                </div>
                <div class="modal-body">
                    <div class="form-inline">
                        <input class="form-control" type="text" id="name" placeholder="<%=GlobalStrings.Name %>" />
                        <button class="btn btn-default" type="button" id="LoadRecordsButton"><i class="fa fa-search"></i></button>
                        <button class="btn btn-default" type="button" id="ResetButton"><i class="fa fa-refresh"></i></button>
                    </div>
                    <p></p>
                    <div id="ServicesTableContainer"></div>
                    <p></p>
                    <a class="btn btn-success" href="../Services/New.aspx" target="_blank"><%=GlobalStrings.AddNew %></a>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->

    <script type="text/javascript">
        $(function () {
            $("#menu-instant").addClass("active");
            $("#menu1-instant").addClass("collapse in");
            $("#instant-ticket").addClass("active");

            $("#<%=txtStartDate.ClientID %>").calendar();
            $("#<%=txtEndDate.ClientID %>").calendar();

            $("#<%=txtServiceName.ClientID %>").prop("disabled", true);

            //Prepare jtable plugin
            $('#ServicesTableContainer').jtable({
                paging: true,
                pageSize: 10,
                sorting: true,
                defaultSorting: 'Code ASC',
                actions: {
                    listAction: '../Services/List.aspx/ServiceList'
                },
                fields: {
                    Id: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    Code: {
                        title: '<%=GlobalStrings.Code %>'
                    },
                    Name: {
                        title: '<%=GlobalStrings.Name %>',
                        width: '20%',
                        display: function (data) {
                            return '<a href="javascript:void(0);" data-dismiss="modal" onclick="javascript:ServiceSelect({Id:' + data.record.Id +
                            ',Code:\'' + data.record.Code + '\'' +
                                ',Name:\'' + escape(data.record.Name) + '\'' +
                                    '});">' + data.record.Name + '</a>';
                        }
                    }
                }
            });

            $('#LoadRecordsButton').click(function (e) {
                e.preventDefault();
                $('#ServicesTableContainer').jtable('load', {
                    name: $('#name').val()
                });
            });

            // enters
            $('#name').keypress(function (e) {
                if (e.which == 13) {
                    e.preventDefault();
                    $('#LoadRecordsButton').click();
                }
            });

            // reset button
            $('#ResetButton').click(function (e) {
                e.preventDefault();
                $('#name').val('');
                $('#LoadRecordsButton').click();
            });
        });
    </script>

    <script type="text/javascript">
        function ServiceSelect(service) {
            $("#<%=hidServiceId.ClientID %>").val(service.Id);
            $("#<%=txtServiceName.ClientID %>").val(unescape(service.Name));
        }

        function SelectService() {
            // load data
            $('#ServicesTableContainer').jtable('load', { name: $('#name').val() });
        }
    </script>
</asp:Content>
